﻿using System;
using System.Collections.Generic;
using EntityObjects;
using BAL.Controller;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;


namespace PresentationLayer.View.DeptRepresentative
{
    public partial class ChangeCollectionPoint : System.Web.UI.Page
    {
        string Id;
        int collectionId;
        CollectionPointControl cpControl;
        DepartmentControl depControl;
        CollectionPoint collectionPoint;
        Department dept;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Id = (string)Session["empID"];
                depControl = new DepartmentControl();
                cpControl = new CollectionPointControl();

                dept = new Department();
                dept=depControl.selectDepartment(Id);

                collectionId = (int)dept.CollectionId;
                collectionPoint = new CollectionPoint();
                collectionPoint = cpControl.selectCollectionPoint(collectionId);
                lblCollectionPoint.Text = collectionPoint.Place.ToString();

                List<CollectionPoint> cp_list = new List<CollectionPoint>();             
                cp_list = cpControl.selectAllCollectionPoint();
                ddNewCollectionPoint.DataSource = cp_list;
                ddNewCollectionPoint.DataTextField = "place";
                ddNewCollectionPoint.DataBind();

            }
        }

        protected void btnChange_Click(object sender, EventArgs e)
        {
            Id = (string)Session["empID"];
            dept = new Department();
            dept.CollectionId = collectionId;
            depControl = new DepartmentControl();
            depControl.updateDepartment(dept,Id);
            Response.Redirect("ChangeCollectionPoint.aspx");          
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("Dept_Master.aspx");
        }

        protected void ddNewCollectionPoint_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblCollectionPoint.Text = ddNewCollectionPoint.SelectedItem.ToString();
        }
       
    }
}